import logging

import pytest

from resource.pom.settings import Settings
from utils.manager import Direction


class Test:
    app = Settings

    @pytest.mark.parametrize('setup_teardown', [app.bundle_name], indirect=True)
    def test(self, setup_teardown, device):
        logging.info('步骤1.进入桌面-设置-系统，点击恢复出厂设置')
        device.start_ability(self.app.bundle_name, self.app.ability_name)
        # 预置一张截图
        device.snapshot_display('settings.jpeg')
        device.dirc_fling(Direction.Down)
        device.click(*self.app.system_item)
        device.refresh_layout()
        device.click_element(device.get_element_by_text('恢复出厂设置'))
        logging.info('预期结果1.进入恢复出厂设置')
        device.refresh_layout()
        device.assert_text_exist('重置设备')

        logging.info('步骤2.点击重置设备')
        reset = device.get_element_by_text('重置设备')
        device.click_element(reset)
        # 第二个页面的重置
        device.click_element(reset)
        logging.info('预期结果2.重置后保存的应用与数据清除，可重新进入桌面')
        device.wait_boot_completed()
        output = device.hdc_shell('ls /data/local/tmp')
        # 检查截图是否还在
        assert 'settings.jpeg' not in output, '数据未清除干净'
